#include "adduserdialog.h"
#include "ui_adduserdialog.h"
#include <QMessageBox>
addUserDialog::addUserDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addUserDialog)
{
    ui->setupUi(this);
    this->setWindowTitle("添加用户数据");
}

addUserDialog::~addUserDialog()
{
    delete ui;
}

QString addUserDialog::getPassword()
{
    return password;
}

QString addUserDialog::getUserName()
{
    return UserName;
}

int addUserDialog::getUserType()
{
    return userType;
}

void addUserDialog::setTitle(QString title)
{
    ui->label->setText(title);
     this->setWindowTitle(title);
}

void addUserDialog::setData(QString val1, QString val2, int type)
{
    if(val1.compare(""))
    ui->edit_username->setEnabled(false);
    else
        ui->edit_username->setEnabled(true);
    ui->edit_username->setText(val1);
    ui->edit_username->setText(val2);
    ui->comboBoxuser_type->setCurrentIndex(type);
}



void addUserDialog::on_pb_add_clicked()
{
    if(!ui->edit_password->text().isEmpty()&& ! ui->edit_username->text().isEmpty())
    {
        password = ui->edit_password->text();
        UserName = ui->edit_username->text();
        userType = ui->comboBoxuser_type->currentIndex();
        this->accept();
    }
    else
    {
        QMessageBox::warning(this,QString("错误")
                              ,QString("请输入完整的信息"),
                              QMessageBox::Ok);
    }
}

void addUserDialog::on_pb_close_clicked()
{
    this->reject();
}
